package com.game.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
        import com.game.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.game.business.mapper.TGroupMapper;
import com.game.business.domain.TGroup;
import com.game.business.service.ITGroupService;
import org.springframework.util.CollectionUtils;

/**
 * 群聊Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-15
 */
@Service
public class TGroupServiceImpl extends ServiceImpl<TGroupMapper,TGroup>  implements ITGroupService
{
    @Autowired
    private TGroupMapper tGroupMapper;

    /**
     * 查询群聊
     *
     * @param id 群聊主键
     * @return 群聊
     */
    @Override
    public TGroup selectTGroupById(Long id)
    {
        return tGroupMapper.selectTGroupById(id);
    }
    @Override
    public TGroup selectTGroupByGroupId(String groupId)
    {
        QueryWrapper<TGroup> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_id",groupId);
        List<TGroup> list = this.list(queryWrapper);
        if(!CollectionUtils.isEmpty( list)){
            return  list.get(0);
        }else{
            return null;
        }
    }


    /**
     * 查询群聊列表
     *
     * @param tGroup 群聊
     * @return 群聊
     */
    @Override
    public List<TGroup> selectTGroupList(TGroup tGroup)
    {
        return tGroupMapper.selectTGroupList(tGroup);
    }

    /**
     * 新增群聊
     *
     * @param tGroup 群聊
     * @return 结果
     */
    @Override
    public int insertTGroup(TGroup tGroup)
    {
                tGroup.setCreateTime(DateUtils.getNowDate());
            return tGroupMapper.insertTGroup(tGroup);
    }

    /**
     * 修改群聊
     *
     * @param tGroup 群聊
     * @return 结果
     */
    @Override
    public int updateTGroup(TGroup tGroup)
    {
                tGroup.setUpdateTime(DateUtils.getNowDate());
        return tGroupMapper.updateTGroup(tGroup);
    }

    /**
     * 批量删除群聊
     *
     * @param ids 需要删除的群聊主键
     * @return 结果
     */
    @Override
    public int deleteTGroupByIds(Long[] ids)
    {
        return tGroupMapper.deleteTGroupByIds(ids);
    }

    /**
     * 删除群聊信息
     *
     * @param id 群聊主键
     * @return 结果
     */
    @Override
    public int deleteTGroupById(Long id)
    {
        return tGroupMapper.deleteTGroupById(id);
    }
}
